package com.irononetech.android.MultilevelListView;

import com.irononetech.android.Application.Application;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.irononetech.android.formcomponent.FormObject;
import com.irononetech.android.formcomponent.view.VehicleDetailsActivity;
import com.irononetech.android.claimsonersa.R;
import android.app.ExpandableListActivity;
import android.content.Intent;
import android.content.res.Resources.NotFoundException;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class ExpList3_Motorcycle extends ExpandableListActivity{

	Logger LOG = LoggerFactory.getLogger(ExpList3_Motorcycle.class);

	private ColorExpListAdapterMotorcycle colorExpListAdapter;
	FormObject fo;  
	static boolean booleanlistMotorcycle[][][][];
	static boolean booleanprelistMotorcycle[][][][];
	Button back;
	EditText otherfield;
	
	static final String listdesc[][][][] = 
		{
		{
			{
				{ "Motorcycle", "All parts" },
				{ "Head Light Lh","" },
				{ "Head Light","" },
				{ "Head Light Cowling","" },
				{ "Visor","" },
				{ "Meter","" },
				{ "Handle","" },
				{ "Front R/H Signal Light","" },
				{ "Front L/H Signal Light","" },
				{ "Front R/H Mirror","" },
				{ "Front L/H Mirror","" },
				{ "Clutch Lever","" },
				{ "Break Lever","" },
				{ "Clutch cable","" },
				{ "Break cable","" },
				{ "Ignition Switch","" },
				{ "Handle Switch Left","" },
				{ "Handle Switch Right","" },
				{ "Front Fork Tube","" },
				{ "Front Fork Seal","" },
				{ "Petrol Tank","" },
				{ "Petrol Tank Lid","" },
				{ "P/Tank cowling (L/R)","" },
				{ "T Column","" },
				{ "Top Column","" },
				{ "Handle Bolt","" },
				{ "Handle cup set upper","" },
				{ "Handle cup set Lover","" },
				{ "Speedometer","" },
				{ "Speedometer cable","" },
				{ "Front Hub","" },
				{ "Front Disk","" },
				{ "Wheel Rim","" },
				{ "Alloy Wheel Rim","" },
				{ "Liver set Front","" },
				{ "Front Tire","" },
				{ "Front Tire Tube","" },
				{ "Front Fender","" },
				{ "Seat","" },
				{ "Seat Cowling (L/R)","" },
				{ "Handle Balancer","" },
				{ "Seat Grip","" },
				{ "Right Side Cover","" },
				{ "Left side cover","" },
				{ "Kick Paddle","" },
				{ "Break Paddle","" },
				{ "Gear Lever","" },
				{ "Right side Front Footrest","" },
				{ "Right side Rear Footrest","" },
				{ "Left side Front Footrest","" },
				{ "Left side Rear Footrest","" },
				{ "Foot-rest Rubber","" },
				{ "Sari Guard","" },
				{ "Swing Arm","" },
				{ "Silencer","" },
				{ "Silencer Guard","" },
				{ "Crash Bar","" },
				{ "Right Fender","" },
				{ "Rear Right Signal Light","" },
				{ "Rear Left signal Light","" },
				{ "Break Light","" },
				{ "Rear Wheel Rim","" },
				{ "Right Alloy Wheel Rim","" },
				{ "Rear Tire","" },
				{ "Rear Tire Tube","" },
				{ "Chain","" },
				{ "Spoke","" },
				{ "Chain Case","" },
				{ "Main Stand","" },
				{ "Side Stand","" },
				{ "Battery","" },
				{ "Footrest Holder RH","" },
				{ "Footrest Holder LH","" },
				{ "Tank Sticker set","" },
				{ "Tail cover Sticker LH/RH","" },
				{ "R Shock Absorber (LH/RH)","" },
				{ "Front panel Top","" },
				{ "Front panel Bottom","" },
				{ "Rear RH Panel Bottom","" },
				{ "Rear LH Panel Bottom","" },
				{ "Rear RH Panel Top","" },
				{ "Rear LH Panel Top","" },
				{ "Break caliper","" },
				{ "Fork Oil","" },
				{ "Head Light Bracket","" },
				{ "R Additional Cover","" },
				{ "Starter Motor","" },
				{ "Break servo Tank","" },
				{ "Chock Cable","" },
				{ "Number Plate","" },
				{ "Side panels (for scooters)","" },
				{ "Top panels (for scooters)","" },
				{ "v-panels (for scooters)","" },
				{ "Center panels (for scooters)","" },
				{ "R/S bottom panels (for scooters)","" },
				{ "L/S bottom pales (for scooters)","" },
				{ "Front buckets (for scooters)","" },
				{ "Back rests","" },
				{ "Rear crash bars","" },
				{ "CDI unit","" },
			},
		}
		};

	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle icicle){

		try {
			super.onCreate(icicle);
			LOG.debug("ENTRY onCreate");
			setContentView(R.layout.multilevel_expandable_list_main);
			fo=Application.getFormObjectInstance();
			back = (Button)findViewById(R.id.button2);
			otherfield = (EditText)findViewById(R.id.damagedItemsOtherField);

			if(fo.getisPreSelected())  //PRE
			{
				otherfield.setText(fo.getpredamagedItemsOtherField());
				booleanprelistMotorcycle = fo.getBooleanprelistMotorcycle();
				colorExpListAdapter = new ColorExpListAdapterMotorcycle(this, getExpandableListView(), listdesc);
				setListAdapter( colorExpListAdapter );

				back.setBackgroundDrawable(getResources().getDrawable(R.drawable.back_button_xml));
			}
			else {
				otherfield.setText(fo.getdamagedItemsOtherField());
				booleanlistMotorcycle = fo.getBooleanlistMotorcycle();
				colorExpListAdapter = new ColorExpListAdapterMotorcycle(this, getExpandableListView(), listdesc);
				setListAdapter( colorExpListAdapter );

				back.setBackgroundDrawable(getResources().getDrawable(R.drawable.cancel_button_xml));
			}
			if(!fo.isEditable()){
				editDisable();
			}
			LOG.debug("SUCCESS onCreate");
		} catch (NotFoundException e) {
			 LOG.error("editEnable:10319");
			   if(e != null){
				LOG.error("Message: " + e.getMessage());
				LOG.error("StackTrace: " + e.getStackTrace());
			  }
		} catch (Exception e) {
			 LOG.error("editEnable:10320");
			   if(e != null){
				LOG.error("Message: " + e.getMessage());
				LOG.error("StackTrace: " + e.getStackTrace());
			  }
		}
	}

	
	public void editDisable() {
		try {
			otherfield.setFocusable(false);

			if(fo.getisPreSelected())  //PRE
			{
				back.setBackgroundDrawable(getResources().getDrawable(R.drawable.back_button_xml));
			} else{
				back.setBackgroundDrawable(getResources().getDrawable(R.drawable.back_button_xml));
			}
		} catch (NotFoundException e) {
			 LOG.error("editEnable:10321");
			   if(e != null){
				LOG.error("Message: " + e.getMessage());
				LOG.error("StackTrace: " + e.getStackTrace());
			  }
		} catch (Exception e) {
			 LOG.error("editEnable:10322");
			   if(e != null){
				LOG.error("Message: " + e.getMessage());
				LOG.error("StackTrace: " + e.getStackTrace());
			  }
		}
	}

	public void editEnable() {
		try {
			otherfield.setFocusable(true);

			if(fo.getisPreSelected())  //PRE
			{
				back.setBackgroundDrawable(getResources().getDrawable(R.drawable.back_button_xml));
			} else{
				back.setBackgroundDrawable(getResources().getDrawable(R.drawable.cancel_button_xml));
			}
		} catch (NotFoundException e) {
			 LOG.error("editEnable:10323");
			   if(e != null){
				LOG.error("Message: " + e.getMessage());
				LOG.error("StackTrace: " + e.getStackTrace());
			  }
		} catch (Exception e) {
			 LOG.error("editEnable:10324");
			   if(e != null){
				LOG.error("Message: " + e.getMessage());
				LOG.error("StackTrace: " + e.getStackTrace());
			  }
		}
	}

	
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			return false;
		}
		return super.onKeyDown(keyCode, event);
	}

	
	public void multilevel_ok_click(View v){
		try{
			if(fo.getisPreSelected())  //PRE
			{
				fo.setBooleanprelistMotorcycle(booleanprelistMotorcycle);
				fo.setpredamagedItemsOtherField(otherfield.getText().toString().trim());
			}
			else{
				fo.setBooleanlistMotorcycle(booleanlistMotorcycle);
				fo.setdamagedItemsOtherField(otherfield.getText().toString().trim());
			}

			Intent mIntent = new Intent(ExpList3_Motorcycle.this, VehicleDetailsActivity.class);
			mIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
			startActivity(mIntent);
			finish();
		}
		catch (Exception e) {
			 LOG.error("multilevel_ok_click:10325");
			   if(e != null){
				LOG.error("Message: " + e.getMessage());
				LOG.error("StackTrace: " + e.getStackTrace());
			  }
		}
	}

	public void multilevel_back_button(View v){
		try {
			if (fo.isEditable()) {
				int p1 = Application.get4DArrSizeSec1();
				int p2 = Application.get4DArrSizeSec2();
				int p3 = Application.get4DArrSizeSec3();
				int p4 = Application.get4DArrSizeSec4();
				boolean[][][][] a = new boolean[p1][p2][p3][p4];
				if(!fo.getisPreSelected()) {
					//Damaged Items
					fo.setisVehicleShow(true);
					fo.setdamagedItemsOtherField("");
					fo.setpredamagedItemsOtherField("");
					fo.setBooleanlistMotorcycle(a);
					fo.setBooleanprelistMotorcycle(a);
				}
				else {
					fo.setBooleanprelistMotorcycle(a);
					fo.setpredamagedItemsOtherField(otherfield.getText().toString().trim());
				}
			}
			finish();
		} catch (Exception e) {
			 LOG.error("multilevel_back_button:10326");
			   if(e != null){
				LOG.error("Message: " + e.getMessage());
				LOG.error("StackTrace: " + e.getStackTrace());
			  }
		}
	}
}